package game;

import game.exceptions.TileException;

/**
 * Class that represents a tile in Rummikub.
 * @author Fishman Yevgeny
 * @date Oct 25, 2009
 */
public class Tile implements Comparable<Tile>{

	private int _number;
	private TileColor _color;
	
	/**
	 * Constructor for a Tile class.
	 * @param number number on the required tile.
	 * @param color color of the required tile.
	 */
	public Tile(int number, TileColor color) throws TileException{
		if ((number >= 0) && (number <= 12)) {
			_number = number;
		}else {
			throw new TileException("Constructor Exception: Tile number should be betwreen 0 and 12.");
		}
		_color = color;
	}
	
	/**
	 * Getter for number.
	 * @return number of the tile.
	 */
	public int getNumber(){
		return _number;
	}
	
	/**
	 * Getter for color.
	 * @return color of the tile.
	 */
	public TileColor getColor(){
		return _color;
	}
	
	@Override
	public boolean equals(Object other){
		return ((other instanceof Tile) && 
				(((Tile)other)._color.equals(this._color)) && 
				(((Tile)other)._number == this._number));
	}
		
	public enum TileColor{
		BLUE,RED,YELOW,BLACK;
	}

	@Override
	public int compareTo(Tile o) {
		if (this._number < o._number) {
			return -1;
		}
		if (this._number > o._number){
			return 1;
		}
		return 0;
	}
	
}
